﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_Quanlylienhe : System.Web.UI.Page
{
    YKIENKHController YkienCTR = new YKIENKHController();
    protected void Page_Load(object sender, EventArgs e)
    {
        if(Session["Employee"] == null)
            Response.Redirect("login.aspx");
        if (!IsPostBack)
        {
            LoadData();
            MultiView1.ActiveViewIndex = 0;
        }
    }

    private void LoadData()
    {
        YkienCTR = new YKIENKHController();
        gvYKien.DataSource = YkienCTR.fnC_GetDataAllYKien();
        DataBind();
    }
    protected void gvYKien_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        HiddenField masp = (HiddenField)gvYKien.Rows[e.RowIndex].Cells[0].FindControl("hdfmasp");
        try
        {
            YkienCTR.Delete(masp.Value);
            LoadData();
        }
        catch { }
    }
    protected void gvYKien_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ImageButton btn = (ImageButton)e.Row.Cells[6].Controls[0];
            btn.OnClientClick = "if(!confirm('Bạn có muốn xóa " + Server.HtmlDecode(e.Row.Cells[1].Text) + "  không?'))return false";
        }
    }
    protected void gvYKien_SelectedIndexChanged(object sender, EventArgs e)
    {
        HiddenField madl = (HiddenField)gvYKien.SelectedRow.Cells[0].FindControl("hdfmasp");
        YKienKhachHangEntity ykien = YkienCTR.GetYKien(madl.Value);
        lbDiaChi.Text = ykien.DiaChi;
        lbDienThoai.Text = ykien.DienThoai;
        lbEmail.Text = ykien.Email;
        lbNgayDang.Text = ykien.NgayGui.ToShortDateString();
        lbNguoiDang.Text = ykien.TenKH;
        lbNoiDung.Text = ykien.NoiDung;
        lbTieuDe.Text = ykien.TieuDe;
        hIdyk.Value = ykien.IdYK.ToString();
        MultiView1.ActiveViewIndex = 1;
    }
    protected void gvYKien_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvYKien.PageIndex = e.NewPageIndex;
        LoadData();
        DataBind(); 
    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        string idyk = hIdyk.Value;
        if (idyk != null)
        {
            YkienCTR.Delete(idyk);
        }
        LoadData();
        MultiView1.ActiveViewIndex = 0;
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = 0;
    }
}